Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable running PyTorch models #207

Merged
merged 85 commits into from
Feb 22, 2024
Merged

Enable running PyTorch models #207

merged 85 commits into from
Feb 22, 2024

Conversation

masahi
Copy link
Member

@masahi masahi commented Feb 14, 2024

This is the first cut toward running PT models under mlc-serve. Things are functional but rough. All we need to do to run a PT model is to replace --local-id llama-2-13b-chat-hf-q0f16 with --local-id models/llama-2-13b-chat-hf (the path to the HF model directory) etc.

  • I haven’t verified that it supports all sampler features that we recently added (logprobs, json etc). Parallel sampling works but evicting parallel-sampling request requires model change.
  • Right now it only supports vLLM models. They are directly loaded via from vllm.model_executor.models.llama import LlamaForCausalLM etc. Models such as phi-2, Qwen run out of the box, in addition to llama-based models and Mixtral that the TVM model also supports. vLLM needs to be installed from https://github.com/octoml/vllm/tree/for-mlc-serve
  • Single-gpu perf is not good. For llama 13B, using benchmark_throughput.py, TVM gets 22.98 requests/s while PT gets 13.78 requests/s. Since TVM and vLLM models should be using the same kernels for matmul and attention, there shouldn't be a big difference in performance. I haven't looked into this issue deeply.
  • Multi-gpu performance is terrible. Currently there is a huge overhead in serialization of inputs from main to worker processes, which can be seen below (large poll between two decode).
    image

@sunggg @yelite @elvin-n @vvchernov @jroesch @binarybana

Copy link
Member

@sunggg sunggg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, Masa! A couple comments.

serve/mlc_serve/engine/base.py Show resolved Hide resolved
serve/mlc_serve/engine/engine_common.py Outdated Show resolved Hide resolved
block_tables.append(block_table.get_blocks())

if sliding_window:
seq_lens.append(min(seq_len, sliding_window))
else:
seq_lens.append(seq_len)

max_context_len = max(max_context_len, seq_lens[-1])

def _do_pad(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we started considering vllm's tensor layout, what do you think about unifying it? It seems like upstream mlc-llm also uses 2D inputs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this also could help our cuda graph integration?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We haven't verified if 2D inputs is better for performance, and how much cuda graph actually helps.

The upstream input looks like 2D but it is always either (1, num_total_token) or (batch_size, 1). So their 2D input is essentially 1D.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think it is worth visiting imo. But not now, in the future. Although there might not be performance boost, it would be nice to unify the layout with upstream unless there is reason.

serve/mlc_serve/utils.py Show resolved Hide resolved
serve/pyproject.toml Show resolved Hide resolved
serve/mlc_serve/model/torch_model.py Show resolved Hide resolved
@masahi
Copy link
Member Author

masahi commented Feb 20, 2024

Oh I just realized that, after I updated our vLLM work, which made their input representation 2D, memory profiling is broken.

Right now we only have max_num_batched_tokens as a parameter to memory profiling, and "the biggest input" to memory profiling is a batch of max_num_batched_tokens sequences each of which is length 1. But with 2D input, we also need max_seq_len param, since prefill inputs are padded to the max seq len in a batch. So memory profiling severely underestimates memory usage.

We could look into how vLLM does memory profiling currently, but I'm inclined to revert their 2D rep change instead. Either way, this is left for future work.

@masahi
Copy link
Member Author

masahi commented Feb 21, 2024

I opened a ticket to track many TODO items after this PR. #217

I think this is ready to merge for now @sunggg

@sunggg sunggg merged commit a377c3c into octoml:batch-serving Feb 22, 2024
1 check passed
Lunderberg pushed a commit to Lunderberg/mlc-llm that referenced this pull request Feb 27, 2024
* Prioritize arch-specific lib

* Avoid repetitive dlopen when reloading the same model

* handle the case where lib path remains the same
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants